/**
 * @Description:
 * @Author HP
 * @create 2021/8/20 9:01
 */
import { createStore } from 'vuex'
import { useVuexPersistencePlugin } from './plugins/vuex-persist'
import useVuexHelper from '~vuex-helper'
const modules = import.meta.globEager('./modules/*.js')

// 创建一个新的 store 实例
const store = createStore({
  modules: Object.keys(modules).reduce(
    (pre, cur) => ({
      ...pre,
      [cur
        .replace(/^\.\/(.*)\.\w+$/, '$1')
        .split('/')
        .pop()]: modules[cur].default
    }),
    {}
  ),
  plugins: [
    useVuexHelper.plugins(),
    useVuexPersistencePlugin({
      key: 'system_info',
      excludes: []
    })
  ]
})

export default store
